package com.caiju.health.service.impl;

import com.caiju.health.entity.PageResult;
import com.caiju.health.mapper.ICheckItemMapper;
import com.caiju.health.pojo.CheckItem;
import com.caiju.health.service.ICheackItemService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CheckItemServiceImpl implements ICheackItemService {
    @Resource
    private ICheckItemMapper cheackItemMapper;
    @Override
    public PageResult findCheckItemByCondition(Integer currentPage, Integer pageSize, String queryString) {
        if (currentPage==null){
            currentPage = 1;
        }
        if (pageSize==null){
            pageSize = 5;
        }
        Page<Object> page = PageHelper.startPage(currentPage,pageSize);
//        queryString="null" ,误以为有值
        if(queryString.equals("null")){
            queryString = null;
        }else {
            queryString = "%" + queryString + "%";
        }
        List<CheckItem> checkItemList = cheackItemMapper.findCondition(queryString);
        PageResult pageResult = new PageResult(page.getTotal(),checkItemList);
        return  pageResult;
    }


    @Override
    public void addCheckItem(CheckItem checkItem){
        cheackItemMapper.insertCheckItem(checkItem);
    }

    @Override
    public void updateCheckItem(CheckItem checkItem) {
        cheackItemMapper.updateCheckItem(checkItem);
    }

    @Override
    public void deleteCheckItem(Integer id) {
        cheackItemMapper.updateCheckItemByStatus(id);
    }

    @Override
    public CheckItem findCheckItemById(Integer id) {
        CheckItem checkItem =  cheackItemMapper.findCheckItemById(id);
        return checkItem;
    }

    @Override
    public List<CheckItem> findAllCheckItem() {
        List<CheckItem> checkItemList =  cheackItemMapper.findAllCheckItem();
        return checkItemList;
    }

}
